<?php


namespace App\Http\Controllers\Drivers\V2\Index;


use App\Http\Controllers\Controller;
use App\Services\CarService;
use App\Services\DriversIndexService;
use App\Services\DriversOrderService;
use App\Services\UsersService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

/**
 * Class IndexController
 * @package App\Http\Controllers\Drivers\V2\Index
 * 首页数据
 */
class IndexController extends Controller
{
    /**
     * 首页数据统计
     */
    public function index_list_count(Request $request, DriversIndexService $service)
    {
        $info = $service->index_order_count(Auth::user());

        return $this->sendJson($info);
    }

    /**
     * 接口整合
     */
    public function index_list_count_pass_status(DriversIndexService $service, UsersService $usersService, CarService $carService)
    {
        $user = Auth::user();
        $info = $service->index_order_count($user); //订单首页数据统计
        $res = $usersService->password_check($user); //司机所有状态监测
        $car = $carService->getList($user); //司机车辆列表
        return $this->sendJson(compact('info', 'res', 'car'));
    }

    /**
     * @param Request $request
     * @param DriversIndexService $service
     * @return IndexController|\Illuminate\Http\JsonResponse
     * 选单统计数量
     */
    public function driver_count(Request $request, DriversIndexService $service)
    {
        $car_id = (int)$request->post('car_id', '');
        $type = (string)$request->post('type', '0');
        $list = $service->driverMenu(Auth::user(), $car_id, $type);
        return $this->sendJson($list);
    }

    /**
     * 查找司机是否有进行中的订单
     */
    public function order_status(DriversOrderService $service)
    {
        $user = Auth::user();
        $driver_id = UsersService::driver_id($user); //司机ID
        if (!$driver_id) {
            return $this->sendError('司机ID不存在');
        }
        return $this->sendJson($service->order_info_status($driver_id));
    }

    /**
     * 版本检测
     */
    public function version_status(Request $request, DriversIndexService $service)
    {
        $version = (int)$request->post('version', 1);
        return $this->sendJson($service->version_status($version));
    }
}